package com.coderedma.core.io;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

/**
 * @Author coderedma
 * @Desc
 * @createTime 2024/7/29 14:53
 * @since 1.0.0
 */
public class ClassPathResource implements Resource{

    private final String path;

    public ClassPathResource(String path) {
        this.path = path;
    }

    @Override
    public InputStream getInputStream() throws IOException {
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(this.path);
        if (inputStream == null) {
            throw new IOException("Could not open InputStream for path [" + this.path + "]");
        }
        return inputStream;
    }
}
